home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / FreshBar / Source / TextMeasure.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-25  |  1.5 KB  |  78 lines

  1. //****************************************************************//
  2. // Filename:    TextMeasure.cpp
  3. // Autor:       Christian Taulien of Strange Intelligence
  4. // Purpose:     implementation of a class for measuring texts
  5. // Creation:    19. Mai 1998
  6. //****************************************************************//
  7.  
  8. #include <clib/graphics_protos.h>
  9.  
  10. #include "global.h"
  11. #include "TextMeasure.h"
  12.  
  13. TextMeasureC::TextMeasureC(struct Screen *arg_poScreen)
  14. /*S*/
  15. {
  16.   TRACE("Entry");
  17.   // den TextFont-Ptr auf NULL und dann den Screen setzen
  18.   m_poTextFont = NULL;
  19.   setScreen(arg_poScreen);
  20. }
  21. /*E*/
  22. TextMeasureC::~TextMeasureC()
  23. /*S*/
  24. {
  25.   TRACE("Entry");
  26.   // einfach den Font auf NULL setzen
  27.   setScreen(NULL);
  28. }
  29. /*E*/
  30. int TextMeasureC::getTextHeight()
  31. /*S*/
  32. {
  33.   TRACE("Entry");
  34.   if (!isOk())
  35.   {
  36.     return 8; // topaz-height
  37.   } // if
  38.  
  39.   return m_poTextFont->tf_YSize;
  40. }
  41. /*E*/
  42. int TextMeasureC::getTextWidth(StringC &arg_roText)
  43. /*S*/
  44. {
  45.   TRACE("Entry");
  46.   if (!isOk())
  47.   {
  48.     return arg_roText.getLength()*8; // topaz-width
  49.   } // if
  50.  
  51. return TextLength(&m_oTextRP, (char *) arg_roText, arg_roText.getLength());
  52. }
  53. /*E*/
  54. void TextMeasureC::setScreen(struct Screen *arg_poScreen)
  55. /*S*/
  56. {
  57.   TRACE("Entry");
  58.   // wenn noch ein Font offen.
  59.   if (m_poTextFont)
  60.   {
  61.     CloseFont(m_poTextFont);
  62.     m_poTextFont = NULL;
  63.   } // if
  64.  
  65.   InitRastPort(&m_oTextRP);
  66.  
  67.   if (arg_poScreen)
  68.   {
  69.     m_poTextFont = OpenFont(arg_poScreen->Font);
  70.     if (isOk())
  71.     {
  72.       SetFont(&m_oTextRP, m_poTextFont);
  73.     } // if
  74.   } // if
  75. }
  76. /*E*/
  77.  
  78.